package core.manager
{
import core.Language;

import framework.core.ComponentBuilder;

import values.ui_assets.UIAssetSettingValue;

public class UIAssetsManager
{	
	public static function initialize():void
	{
		
	}
	
	public static function getAssetDefination(key:String):*
	{		
		return UIAssetSettingValue.getByKey(key).property;
	}
	
	public static function createAsset(key:String):*
	{
		var def:XMLList = getAssetDefination(key);
		return createAssetByDef(def);
	}
	
	public static function createAssetByDef(def:XMLList):*
	{
		var asset:* = ComponentBuilder.createByDefineName(def.@classRef);
		
		for each (var node:* in def.children())
		{
			var name:String = node.name();
			if (asset.hasOwnProperty(name))
			{
				if (String(node).indexOf("@") == 0)
				{
					asset[name] = Language.getText(String(node));
				}
				else
				{
					asset[name] = node;
				}
			}
		}
		return asset;
	}
	
	public static function createMCGameObject(key:String):*
	{
		var def:XMLList = getAssetDefination(key);
		var asset:* = ComponentBuilder.createNonDisplayObject(def.@classRef);
		
		for each (var node:* in def.children())
		{
			var name:String = node.name();
			if (asset.hasOwnProperty(name))
			{
				if (String(node).indexOf("@") == 0)
				{
					asset[name] = Language.getText(String(node));
				}
				else
				{
					asset[name] = node;
				}
			}
		}
		return asset;
	}
	
}
}